<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style>
        thead tr th{text-align: center!important;}
        tr td{text-align: center!important;}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
            	<form id="seachFrom" class="layui-form">
	                <div class="layui-card-body">
	                	<input type="hidden" name="id" value="${seckillId }"/>
	                    <div class="layui-container" style="padding-bottom: 50px">
	                        <div class="layui-col-md12">
	                            <div class="layui-col-md3 layui-col-md-offset4">
	                                <div class="layui-col-sm5">
	                                    <button class="layui-btn layui-btn layui-btn-warm editThis" type="button" data-id="${seckillId}">添加商品</button>
	                                </div>
	                                <div class="layui-col-sm5">
	                                    <a class="layui-btn layui-btn layui-btn" href="javaScript:;" onclick="history.go(-1)">返回上一页</a>
	                                </div>
	                            </div>
	                        </div>
	                        <div class="layui-col-md12"><hr></div>
	                    </div>
	                    <table class="layui-table">
	                        <thead>
	                        <tr>
	                            <th>商品编码</th>
	                            <th>商品名称</th>
	                            <th>规格名称</th>
	                            <th>商品原价</th>
	                            <th>秒杀价</th>
	                            <th>参与总数</th>
	                            <th>每人<br>限购数</th>
	                            <th>已抢购</th>
	                            <th>排序</th>
	                            <th>操作</th>
	                        </tr>
	                        </thead>
	                        <tbody>
	                        <c:forEach items="${pageInfo.records}" var="l">
	                            <tr>
	                                <td width="5%">${l.proCode}</td>
	                                <td width="12%">${l.proName}</td>
	                                <td width="12%">${l.specName}</td>
	                                <td width="8%">${l.price}</td>
	                                <td width="8%" style="color: red">${l.seckillPrice}</td>
	                                <td width="5%">${l.totalNum}</td>
	                                <td width="6%">${l.limitNum}</td>
	                                <td width="6%">${l.buyNum}</td>
	                                <td width="5%">${l.sort}</td>
	                                <td width="5%">
	                                    <c:if test="${l.status==0}">
	                                        <button data-id="${l.id}" data-buy="${l.buyNum}" data-total="${l.totalNum}" data-type="returnStock"
	                                                type="button" class="layui-btn layui-btn-sm layui-btn-danger returnStock">返回库存</button>
	                                    </c:if>
	                                </td>
	                            </tr>
	                        </c:forEach>
	                        </tbody>
	                    </table>
	                    <div class="test-table-reload-btn" style="margin-top: 10px;">
	                        <%@include file="../paging.jsp" %>
	                    </div>
	                </div>
	        	</form>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'laydate','form'], function(){
        var laydate = layui.laydate,form=layui.form;

        var active = {
            returnStock:function (id) {
                layer.confirm('确定操作吗？', function(){
                    $.ajax({
                        url: "/activity/handleSeckillReturnStock",
                        data: {"id":id},
                        dataType: "json",
                        type: "post",
                        success: function (data) {
                            if(data.status){
                                layer.msg(data.desc,{icon:1});
                                setTimeout(function () {
                                    window.location.reload();
                                }, 1000)
                            }else{
                                layer.msg(data.desc,{icon:2});
                            }
                        }
                    });
                });
            },
            editThis:function(id){
                var index = layer.open({
                    title:'新增秒杀活动商品',
                    type: 2,
                    area: ['800px', '500px'],
                    maxmin: true,
                    content: '/activity/addSeckillDetail?seckillId='+id
                });
                layer.full(index);
            }
        };
        $('.returnStock').on('click',function () {
            var type = $(this).data('type');
            var id = $(this).data('id');
            var buy = $(this).data('buy');
            var total = $(this).data('total');
            var left = total - buy;
            if(left < 1){
                layer.msg("该商品没有可返回库存！");
                return;
            }
            active[type] && active[type].call(this,id);
        });
        $('.editThis').on('click',function () {
            var type = 'editThis';
            var id = $(this).data('id');
            active[type] && active[type].call(this,id);
        })
    });
</script>
</body>
</html>